package com.hugoo.form.xo;

import com.hugoo.core.util.TL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Lovelock.Chan
 */
public class XHandle extends XVar {

    @Override
    public String getParentDbl() {
        return this.getxForm().getDbl();
    }

    public enum DBMODL {

        AUTO, BATCH, CUSTOM
    }

    public enum RtnYpe {

        PGE, CST, XLS, TXT, XLSX, XLST
    }
    //资源
    private String rtn;
    private String rtnype;//返回类型、1：【pge】页面、2：【cst】自定义
    //角色，在指定某个角色的情况下，只有被指定的用户才能进行数据操作
    private String modl;//数据库语句执行模式 1、自动提交 2、批处理 3、自定义
    private String roles;
    private String expCols;
    private String expColsType;//导出列类型（用于动态导出支持）./static(固定值,缺省)/auto(动态变量模式)/mem(内存变量模式)/
    private String expFmt;//NTNE/YTYE/
    private String xslt;
    private String fileName;
    private String saveCList;//缓存列表
    private String chkey;//缓存
    private String clearCList;//清除缓存列表
    private String authz;//认证模式：none不用认证 basic基本信息认证
    private Map<String, XSql> xSqlMap = new HashMap();
    private final List<XSql> xSqlList = new ArrayList();
    private XForm xForm;

    public void addXSql(XSql xsql) {
        xsql.setxHandle(this);
        xSqlMap.put(xsql.getId(), xsql);
        xSqlList.add(xsql);
    }

    public DBMODL getModl() {
        if (TL.isEmpty(modl)) {
            return DBMODL.AUTO;
        } else if ("BATCH".equalsIgnoreCase(modl)) {
            return DBMODL.BATCH;
        } else if ("CUSTOM".equalsIgnoreCase(modl)) {
            return DBMODL.CUSTOM;
        }
        return DBMODL.AUTO;
    }

    public boolean isCacheRST() {
        if (TL.isEmpty(chkey) || "NONE".equalsIgnoreCase(chkey)) {
            return false;
        }
        return true;
    }

    public String getChkey() {
        return chkey;
    }

    public void setChkey(String chkey) {
        this.chkey = chkey;
    }


    public String getSaveCList() {
        return saveCList;
    }

    public void setSaveCList(String saveCList) {
        this.saveCList = saveCList;
    }

    public String getClearCList() {
        return clearCList;
    }

    public void setClearCList(String clearCList) {
        this.clearCList = clearCList;
    }

    public void setModl(String modl) {
        this.modl = modl;
    }

    public XForm getxForm() {
        return xForm;
    }

    public String getXslt() {
        return xslt;
    }

    public void setXslt(String xslt) {
        this.xslt = xslt;
    }

    public String getExpFmt() {
        return expFmt;
    }

    public void setExpFmt(String expFmt) {
        this.expFmt = expFmt;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public void setxForm(XForm xForm) {
        this.xForm = xForm;
    }

    public RtnYpe getRtnYpe() {
        if (TL.isEmpty(rtnype)) {
            return RtnYpe.CST;
        } else if ("PGE".equalsIgnoreCase(rtnype)) {
            return RtnYpe.PGE;//针对写错，或者不写的情况，均视为自定义返回模式
        } else if ("XLS".equalsIgnoreCase(rtnype)) {
            return RtnYpe.XLS;//Excle 2003文件类型导出
        } else if ("TXT".equalsIgnoreCase(rtnype)) {
            return RtnYpe.TXT;//txt文件类型导出
        } else if ("XLSX".equalsIgnoreCase(rtnype)) {
            return RtnYpe.XLSX;//Excle 2007文件类型导出
        } else if ("XLST".equalsIgnoreCase(rtnype)) {
            return RtnYpe.XLST;//Excel 2003定制模板导出
        }
        return RtnYpe.CST;
    }

    public String getRtnype() {
        return rtnype;
    }

    public void setRtnype(String rtnype) {
        this.rtnype = rtnype;
    }

    public String getRoles() {
        return roles;
    }

    public void setRoles(String roles) {
        this.roles = roles;
    }

    public String getRtn() {
        return rtn;
    }

    public void setRtn(String rtn) {
        this.rtn = rtn;
    }

    public String getAuthz() {
        return authz;
    }

    public void setAuthz(String authz) {
        this.authz = authz;
    }

    public Map<String, XSql> getxSqlMap() {
        return xSqlMap;
    }

    public List< XSql> getxSqlList() {
        return xSqlList;
    }

    public void setxSqlMap(Map<String, XSql> xSqlMap) {
        this.xSqlMap = xSqlMap;
    }

    public String getExpCols() {
        return expCols;
    }

    public void setExpCols(String expCols) {
        this.expCols = expCols;
    }

    public ExpColsType getExpColsType2() {
        if (expColsType == null) {
            return ExpColsType.STATIC;
        } else if ("auto".equalsIgnoreCase(expColsType)) {
            return ExpColsType.AUTO;
        } else if ("mem".equalsIgnoreCase(expColsType)) {
            return ExpColsType.MEM;
        }
        return ExpColsType.STATIC;
    }

    public String getExpColsType() {
        return expColsType;
    }

    public void setExpColsType(String expColsType) {
        this.expColsType = expColsType;
    }

    public enum ExpColsType {

        STATIC, AUTO, MEM
    }
}
